package com.chinasoft.controller;

import com.chinasoft.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserController {

    @RequestMapping(value = "/save",method = RequestMethod.POST)
    @ResponseBody
    public User save(@RequestBody User user){

        System.out.println("user = " + user);

        User u = new User();
        u.setName("hmm");
        u.setAge(18);
        return u;
    }


    @RequestMapping(value = "/ajaxReturnJson",method = RequestMethod.POST)
    @ResponseBody
    public User ajaxReturnJson(){
        User u = new User();
        u.setName("hmm");
        u.setAge(18);
        return u;
    }

    @RequestMapping(value = "/ajaxReturnJsonList",method = RequestMethod.POST)
    @ResponseBody
    public List<User> ajaxReturnJsonList(){
        User u1 = new User();
        u1.setName("hmm");
        u1.setAge(18);
        User u2 = new User();
        u2.setName("lilei");
        u2.setAge(18);
        ArrayList a = new ArrayList();
        a.add(u1);
        a.add(u2);
        return a;
    }
}